﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Diagnostics;
using CommonDB;

namespace SqliteTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            GetData();
        }

        private void GetData()
        {
            try
            {
                DataProviderImpl dataProvider = new DataProviderImpl();
                DataTable dt = dataProvider.GetDataTest();
                this.dataGridView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string id = txtID.Text.Trim();
                string name = txtName.Text.Trim();
                string age = txtAge.Text.Trim();
                string addr = txtAddress.Text.Trim();
                string salary = txtSalary.Text.Trim();

                DataProviderImpl dataProvider = new DataProviderImpl();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                if (this.checkBox1.Checked)
                {
                    dataProvider.InsertBatchDataTest(id, name, age, addr, salary);
                }
                else
                {
                    int i = dataProvider.InsertDataTest(id, name, age, addr, salary);
                }
                sw.Stop();
                MessageBox.Show(string.Format(@"添加成功！耗时：{0}秒", sw.ElapsedMilliseconds));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            GetData();
        }
    }
}